Skip to content

[200_58] 缺失函数提示增强#655

Merged
wumoin merged 4 commits intomainfrom
wumo/200_58/doc-hint-errors
Apr 3, 2026
Merged

[200_58] 缺失函数提示增强#655
wumoin merged 4 commits intomainfrom
wumo/200_58/doc-hint-errors

Conversation

@wumoin
Copy link
Copy Markdown
Contributor

@wumoin wumoin commented Apr 3, 2026

No description provided.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 3, 2026

Greptile Summary

This PR enhances the "unbound variable" error experience in Goldfish by scanning *load-path* at error time to determine whether the missing symbol is exported by one library, multiple libraries, or none, then printing an appropriate import hint or fallback suggestion. It also propagates s7_scheme* through all error-display call sites, adds the g_function-libraries Scheme primitive, fixes a missing (liii path) import in gf source, and expands the test suite with both shell-level and unit-level coverage.

Confidence Score: 5/5

Safe to merge; remaining findings are P2 style/cleanup suggestions that don't affect correctness.

All logic is correct and well-tested. The two flagged items (redundant loop iteration on the operator and manual port cleanup) are both P2 style concerns with no observable impact on behaviour in the current S7 configuration.

src/goldfish.hpp — two minor style notes in the new helper functions.

Important Files Changed

Filename Overview
src/goldfish.hpp Core change: adds g_function-libraries Scheme function and rewires all error-display paths to pass s7_scheme*, enabling runtime load-path scanning to produce smarter "unbound variable" hints (single library, multiple libraries, or fallback doc hint). Two minor style issues found: redundant operator traversal in goldfish_form_contains_called_symbol and manual (non-RAII) port cleanup in source_file_exports_function.
tests/goldfish/scheme/doc-hint-test.scm Expanded from a single-scenario shell-command test to five scenarios covering unknown function, single-library match, multi-library match, nested expression, and REPL. Tests look correct; cleanup is handled via dynamic-wind.
tests/goldfish/scheme/function-libraries-test.scm New unit test for g_function-libraries. Creates a controlled temporary load-path fixture, exercises unique/shared/renamed/invisible/numeric-part/type-error cases, and restores state with dynamic-wind. Well-structured.
devel/200_58.md New development doc following the devel/x_y.md template. Describes the feature, lists expected outputs for all five scenarios, and notes the bonus gf source fix.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Scheme error captured\nto error port] --> B[goldfish_render_scheme_error_message]
    B --> C[goldfish_format_scheme_error_message\nformat raw error text]
    C --> D[goldfish_append_doc_hint_if_needed]
    D --> E{contains\n'unbound variable'?}
    E -- No --> F[return as-is]
    E -- Yes --> G[goldfish_extract_unbound_function_name_from_error\nextract symbol name]
    G --> H{direct call?\nin open-paren form}
    H -- Yes direct --> I[symbol extracted]
    H -- No --> J[goldfish_extract_error_expression\nparse error context]
    J --> K[goldfish_error_expression_contains_function_call\nAST check via s7_read]
    K -- found in call position --> I
    K -- not found --> F
    I --> L[find_function_libraries_in_load_path\nscan *load-path* .scm files]
    L --> M{how many\nlibraries found?}
    M -- 0 --> N["Hint: try gf doc fn\n+ git grep suggestion"]
    M -- 1 --> O["Hint: fn exists in lib\nPlease import lib"]
    M -- many --> P["Hint: fn exists in multiple libs\nTry: gf doc lib fn for each"]
Loading

Reviews (1): Last reviewed commit: "wip" | Re-trigger Greptile

Comment on lines +3506 to +3510
for (s7_pointer iter= form; s7_is_pair (iter); iter= s7_cdr (iter)) {
if (goldfish_form_contains_called_symbol (sc, s7_car (iter), function_name)) {
return true;
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Redundant traversal of the operator

The for loop starts from iter = form instead of s7_cdr(form), so s7_car(form) (the operator) is visited twice: once by the explicit symbol check just above, and once by the loop's first iteration. The recursive call on a symbol always returns false (symbols aren't pairs), so this doesn't produce wrong results, but it is a minor unnecessary traversal.

Suggested change
for (s7_pointer iter= form; s7_is_pair (iter); iter= s7_cdr (iter)) {
if (goldfish_form_contains_called_symbol (sc, s7_car (iter), function_name)) {
return true;
}
}
for (s7_pointer iter= s7_cdr (form); s7_is_pair (iter); iter= s7_cdr (iter)) {
if (goldfish_form_contains_called_symbol (sc, s7_car (iter), function_name)) {
return true;
}
}

Comment on lines +4882 to +4889
string source_text= read_text_file_exact (source_file);
s7_pointer port = s7_open_input_string (sc, source_text.c_str ());
s7_pointer eof_object = s7_eof_object (sc);

while (true) {
s7_pointer form= s7_read (sc, port);
if (form == eof_object) break;
if (define_library_form_exports_function (sc, form, function_name, group, library)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 No RAII for S7 input port in source_file_exports_function

The port opened by s7_open_input_string is closed manually on both return true and return false paths, but if s7_read or define_library_form_exports_function causes a non-local exit (e.g., S7's internal error handling in some build configurations), s7_close_input_port will be skipped. S7 string ports are GC-managed, so this is unlikely to leak OS resources, but a RAII wrapper or a local guard object would make the lifetime management explicit and safe.

Copy link
Copy Markdown
Contributor

@da-liii da-liii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@wumoin wumoin merged commit c1facb4 into main Apr 3, 2026
4 checks passed
@wumoin wumoin deleted the wumo/200_58/doc-hint-errors branch April 3, 2026 04:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants